#conding:utf-8

from util.operate_excel import OperationExcel
from data.data_config import *
from util.operation_json import OperationJson
class GetData:
    def __init__(self):
        self.operation_excel=OperationExcel()
        # 获取行数
    def get_case_lines(self):
        return self.operation_excel.get_lines()
    # 检查是否执行
    def get_is_run(self,row):
        flag=None
        col=int(get_run())
        run_model=self.operation_excel.get_cell_value(row,col)
        # print("输出执行方式打印"+run_model)
        if run_model=='yes':
            flag=True
        else:
            flag=False
        return flag
    #是否携带表头
    def is_header(self,row):
        col=int(get_header())
        header=self.operation_excel.get_cell_value(row,col)
        # print(header)
        # 判断是需要token
        if header=='yes':
            # print(get_header_value())
            return get_header_value(header)
        # 判断不需要token
        else:
            return get_header_value(header)
            # return None

        #获取请求方式
    def get_request_method(self,row):
        col=int(get_run_way())
        request_method=self.operation_excel.get_cell_value(row,col)
        return  request_method
    #获取请求方式
    def get_request_url(self,row):
        col=int(get_urll())
        url=self.operation_excel.get_cell_value(row,col)
        return url
    # 获取请求参数数据
    def get_request_data(self,row):
        col=int(get_data())
        data=self.operation_excel.get_cell_value(row,col)
        if data == 'NO':
            print("None")
            return None
        else:
            # print("*****data")
            return  data
        # return data


    #通过获取关键字参数进行json文件中拿到data数据
    def get_data_for_json(self,row):

        opera_json=OperationJson()
        request_data=self.get_request_data(row)
        if request_data =='':
            print(request_data)
            return None
        else:
            return opera_json.get_data(self.get_request_data(row))
        # if opera_json.get_data(self.get_request_data(row)) =='None':
        #     return None
        # else:
        #     return opera_json.get_data(self.get_request_data(row))

    #获取预期结果
    def get_expcet_data(self,row):
        col=int(get_expect())
        expect=self.operation_excel.get_cell_value(row,col)
        if expect=='':
            return None
        return expect
    # 返回表头
    def is_heade(self):
            return get_header_value()
    # 写入结果
    def write_result(self,row,value):
         col=int(get_result())
         self.operation_excel.write_value(row,col,value)
    #获取依赖数据的key
    def get_depend_key(self,row):
        col=int(get_data_depend())
        depent_key = self.operation_excel.get_cell_value(row,col)
        # print(depent_key)
        # depent_key=self.operation_excel.get_cell_value(row,col)
        # print(depent_key)
        if depent_key =="":
            return None
        else:
            # print(depent_key)
            return depent_key
    #判断是否有依赖
    def is_depend(self,row):
        col=int(get_field_depend())
        depend_case_id=self.operation_excel.get_cell_value(row,col)
        if depend_case_id =="":
            return None
        else:
            return depend_case_id
    #获取数据依赖字段
    def get_depend_field(self,row):
        col=int(get_field_depend())
        data=self.operation_excel.get_cell_value(row,col)
        if data =="":
            # print("++++++++test++++++")
            return None
        else:
            return data
    def get_write_token(self,row):
        # 获取某一个列
        col= int(gat_token())
        # 获取数据data
        data = self.operation_excel.get_cell_value(row, col)
        return data
    # 获取case_id
    def get_case_id(self,row):
        # 获取某一个列
        col=int(get_case_depend())
        # 获取数据data
        data=self.operation_excel.get_cell_value(row,col)
        # 判断数据是否为空
        if data ==None:
            return True
            # return True
        else:
            return data



if __name__=='__main__':
    oper=GetData()
    # print(oper.get_case_id(2))
    # print(oper.get_data_for_json(2))

    # oper.get_request_data(1)
    # print(oper.get_request_data(2))
    # print(oper.get_depend_key(3))
    # print(oper.get_depend_field(3))
    # print(oper.is_heade())
    # print(oper.get_write_token(1))
